/**
 * 
 */
package org.vsg.common.biz.uid;

/**
 * @author Bill vison
 *
 */
public class UnifiedIDManagerImpl implements UnifiedIDManager {
	
	
	private UnifiedIDProvider provider;
	
	public UnifiedIDProvider getProvider() {
		return provider;
	}

	public void setProvider(UnifiedIDProvider provider) {
		this.provider = provider;
	}

	/* (non-Javadoc)
	 * @see org.vsg.common.biz.uid.UnifiedIDManager#getUid()
	 */
	@Override
	public String genUid() {
		
		if (provider.isSupportAlgorithm() ) {
			return provider.getUid();
		} else {
			return UIDHelper.degistUUID(provider.getUid(), provider.getAlgorithm());
		}

	}

	/* (non-Javadoc)
	 * @see org.vsg.common.biz.uid.UnifiedIDManager#getUid(java.lang.String)
	 */
	@Override
	public String genUid(String prfix) {
		// TODO Auto-generated method stub
		String gId = genUid();
		if (prfix != null) {
			return prfix + gId;
		}
		return gId;
	}

	/* (non-Javadoc)
	 * @see org.vsg.common.biz.uid.UnifiedIDManager#getUid(java.lang.String, java.lang.String)
	 */
	@Override
	public String genUid(String prefix, String suffix) {
		// TODO Auto-generated method stub
		String gId = genUid();
		
		StringBuilder idBuilder = new StringBuilder();
		if (prefix != null) {
			idBuilder.append( prefix );
		}
		idBuilder.append(gId);
		if (suffix != null) {
			idBuilder.append( suffix );
		}
		
		
		
		return idBuilder.toString();
	}

}
